const path = require('path'); //引入path模块
const PrerenderSPAPlugin = require('prerender-spa-plugin');   //预渲染插件
const Renderer = PrerenderSPAPlugin.PuppeteerRenderer;  // 预渲染器

function resolve(dir){
  return path.join(__dirname,dir) //path.join(__dirname)设置绝对路径
}

module.exports={
  // publicPath: '/vue_node_server/dist',
  chainWebpack:(config)=>{    //set第一个参数：设置的别名，第二个参数：设置的路径
    config.resolve.alias
      .set('@',resolve('./src'))
      .set('components',resolve('./src/components'))
      .set('views',resolve('./src/views'))
      .set('assets',resolve('./src/assets'))
      .set('network',resolve('./src/network'))
      .set('common',resolve('./src/common'))
  },
  configureWebpack: config => {
    if (process.env.NODE_ENV !== 'production') return;
    return {
      plugins: [
        new PrerenderSPAPlugin({
          staticDir: path.join(__dirname, './dist'),
          routes: ['/', '/home', '/category', '/cart'],
          renderer: new Renderer({
            inject: {
              foo: 'bar'
            },
            headless: false,
            renderAfterDocumentEvent: 'custom-render-trigger',
          })
        })
      ]
    }
  },
};
